package br.edu.granbery.indianostore.dao;

import br.edu.granbery.indianostore.dao.DaoFactory;
import br.edu.granbery.indianostore.model.Carrinho;
import java.util.List;
import org.hibernate.Session;

/**
 *
 * @author Luiz
 */
public class CarrinhoDao {

    private Session session;

    CarrinhoDao(Session session) {
        this.session = session;
    }

    public List<Carrinho> buscar() {
        return this.session.createCriteria(Carrinho.class).list();
    }

    public Carrinho buscar(int id) {
        return (Carrinho) this.session.load(Carrinho.class, id);
    }

    public boolean inserir(Carrinho carrinho) {
        try {
            this.session.save(carrinho);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public boolean atualizar(Carrinho carrinho) {
        try {
            this.session.merge(carrinho);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public boolean remover(Carrinho carrinho) {
        try {
            this.session.delete(carrinho);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public void destruir(Carrinho carrinho) {
        this.session.evict(carrinho);
    }

    public void destruirList(List<Carrinho> carrinho) {
        this.session.evict(carrinho);
    }
}

